# -*- coding: utf-8 -*-
"""
Created on Tue Jun  5 21:16:41 2018

@author: Administrator

"""

#%%
#prepare data
from agilepipe.organize.raw2fslvbm import Regular2dpabi

raw_dirpath = r'/media/root/MyPassport/T1Img'
excel_filepath = r'/media/root/MyPassport/sub_id.xlsx'
output_dirpath = r'/media/root/MyPassport/vbm_control_failed_successed'
core_percent = 6

Regular2dpabi(raw_dirpath,excel_filepath,output_dirpath,core_percent)

#%% being cautious
#!!!!!!!!!!!!!!!!!!!!!!
'''
if Fslvbm_1_bet   Fslvbm_2_template   Fslvbm_3_proc was failed or interrupted,
the code:'ln -sf /root/anaconda2/envs/py3/bin/python3.7  /root/anaconda2/envs/py3/bin/python'
must be run in the shell
'''
#!!!!!!!!!!!!!!!!!!!!!

#%%

work_diapath = r'/media/root/MyPassport/vbm_control_failed_successed'

#%%
from agilepipe.process.vbmfsl import Template_list

input_dirpath = work_diapath
group_tag_list = ['Control','Failed','Successed']
Template_list([input_dirpath,group_tag_list])

#%%
#from agilepipe.process.vbmfsl import Design_mat_con
#
#Design_mat_con([])

#%%
from agilepipe.process.vbmfsl import Fslvbm_1_bet

input_dirpath = work_diapath
bet_para = ' -N'  #has litte neck:'-b'   has big neck:'-N'

fslvbm_1_bet = Fslvbm_1_bet([input_dirpath,bet_para])
print('fslvbm_1_bet.stdout_err:',fslvbm_1_bet.stdout_err)


#%%
from agilepipe.process.vbmfsl import Fslvbm_2_template

input_dirpath = work_diapath
template_para = ' -n'   #affine registration:'-a'  non-linear registration:'-n'
fslvbm_2_template = Fslvbm_2_template([input_dirpath,template_para])
print('fslvbm_2_template.stdout_err:',fslvbm_2_template.stdout_err)


#%%
from agilepipe.process.vbmfsl import Fslvbm_3_proc

input_dirpath = work_diapath
fslvbm_3_proc = Fslvbm_3_proc([input_dirpath])
print('fslvbm_3_proc.stdout_err:',fslvbm_3_proc.stdout_err)


#%%  
#from agilepipe.process.vbmfs import Smoothing_sigma
#
#input_dirpath = work_diapath
#sigma = r'3.5'
#Smoothing_sigma([input_dirpath,sigma])

#%%

from agilepipe.statics.designmatrix_fsl import Anova_1way_nlevel_mat

level = 3
group_tag_list = ['Control','Failed','Successed']
cov_excel_filepath = r'/media/root/MyPassport/sub_id.xlsx'
cov_column_name_list = ['age','edu_years']
output_dirpath = r'/media/root/MyPassport/vbm_control_failed_successed'

Anova_1way_nlevel_mat([level,group_tag_list,cov_excel_filepath,cov_column_name_list,output_dirpath])

#%%

from agilepipe.process.vbmfsl import  Randomise
input_dirpath = work_diapath
sigma_filename = r'GM_mod_merg_s3'
permutation_num = '5000'
randomise = Randomise([input_dirpath,sigma_filename,permutation_num])
print('randomise.stdout_err:',randomise.stdout_err)